﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.OleDb;
using DTO;
namespace DAO
{
    public class SanPhamDAO
    {
        public List<DTO.SanPhamDTO> SelectAll()
        {
            List<SanPhamDTO> lst = new List<SanPhamDTO>();
            OleDbConnection conn = DataProvider.ConnectDB();
            conn.Open();
            OleDbCommand cmd=new OleDbCommand("select * from SanPham",conn);
            OleDbDataReader dr = cmd.ExecuteReader();
            while (dr.Read())
            {
                SanPhamDTO sp = new SanPhamDTO();
                sp.MaSP = dr.GetInt32(0);
                sp.TenSP = dr.GetString(1);
                sp.DonGiaTV = dr.GetDouble(2);
                sp.DonGiaKL = dr.GetDouble(3);
                sp.QuyCach = dr.GetString(4);
                sp.DVT = dr.GetString(5);
                sp.SLTon = dr.GetInt32(6);
                sp.DiemCV = dr.GetInt32(7);
                lst.Add(sp);
            }
            conn.Close();
            dr.Dispose();
            cmd.Dispose();
            return lst;
        }
        //public SanPhamDTO LaySPTheoMa(SanPhamDTO sp)
        //{
        //    SanPhamDTO sp_ = new SanPhamDTO();
        //    OleDbConnection conn = DataProvider.ConnectDB();
        //    conn.Open();
        //    OleDbCommand cmd = new OleDbCommand("select * from SanPham where MaSP=" + sp.MaSP.ToString(), conn);
        //    OleDbDataReader dr = cmd.ExecuteReader();
        //    if (dr.Read())
        //    {
        //        sp_.MaSP=dr.
        //    }
        //}

    }
}
